<template>
  <div class="sign-modal-box">
    <common-table ref="table" :columns="histroyRecordConfig.columns" :condition="condition">
      <!--修改内容-->
      <template v-slot:xgnr="{ row }">
        <span>{{row['xgnr'] | filterXgnr}}</span>
      </template>
      <!--要素内容-->
      <template v-slot:factor-info="{ row }">
        <div class="factor">
          <p>联系电话：{{ row.ryysLxdh | filterText }}</p>
          <p>车辆号：{{ row.ryysClh | filterText }}</p>
          <p>网名：{{ row.ryysWm | filterText }}</p>
        </div>
      </template>
    </common-table>
  </div>
</template>

<script>
// import { mapGetters, mapActions } from 'vuex';
import { histroyRecordConfig } from './config';
import { searchHistory } from '@/api/common';

export default {
  name: 'history-record',
  components: {},
  data() {
    return {
      condition: {},
      histroyRecordConfig,
      searchHistory
    };
  },
  props: {
    id: {
      type: String,
      default: ''
    }
  },
  filters: {
    // 修改内容过滤
    filterXgnr(value){
      let result = '';

      if (value){
        let xg_str = value.match(new RegExp((/\[{.*}\]/)));
        let xg_type_str = value.match(new RegExp(/将\[.*\]字段从/));

        if (xg_str){
          xg_str = xg_str[0].split(/\]修改为\[/);
          let from_arr = JSON.parse(xg_str[0]);
          let to_arr = JSON.parse(xg_str[1]);

          result = xg_type_str[0];

          // 循环进行要素类型修改展示
          from_arr.forEach((item, index) => {
            result += `从【${item['ysnr']}】修改为【${to_arr[index]['ysnr']}】；`;
          });
        } else {
          result = value;
        }
      }

      return result;
    }
  },
  methods: {},
  mounted() {
    this.$nextTick(() => {
      this.$refs.table &&
        this.$refs.table.search(
          searchHistory,
          {
            page: 0,
            size: 5,
            sort: JSON.stringify(Object.assign(...histroyRecordConfig.reqCondition.sorts)),
            searchCondition: JSON.stringify([{ name: 'ywid', op: '=', value: this.id, type: '', format: '' }])
          },
          { currentPage: 0, pageSize: 5 }
        );
    });
  }
};
</script>

<style lang="scss" scoped>
.wrap {
}
</style>
